/**
 *
 */
var App = (function () {
    // 初始化
    this.fullscreen = false;
    //显示模式 2d,3d,23d,
    this.viewmode = "3d";

    

    function App(options) { // 属性
       
    }
    
    
    // 初始化
    App.prototype.init = function (options) {
        this.map = new Map({ "app": this });
        this.map2d = this.map.map2d;
        this.map3d = this.map.map3d;

        //应急信息列表
        this.loadalarm();
        //总体图表
        this.loadzttb();
        //横向柱状图
        //this.loadhxztt();
        //纵向柱状图
       // this.loadzxztt();
        //环形图        
       // this.loadhxt();
        //人居环境
        var chartrjhj1 = new chartrjhj();
        chartrjhj1.init();
        //健康卫生
        var chartjkws1 = new chartjkws();
        chartjkws1.init();

        //事件
        this.events();
    }
    App.prototype.events = function (options) {
        var that = this;
        
        $(".mapTip i").on("click", function (e) {
            var data = $(this).attr("data");
            if (data === "fullscreen") {
                that.fullscreen = !that.fullscreen;
                $(document).fullScreen(that.fullscreen);
            } else if (data === "23d") {
                //使用23维度切换显示
                that.map.map3d.ol3d.setEnabled(!that.map.map3d.ol3d.getEnabled());

            } else if (data === "dxt") { 
            
            } else if (data === "yxt") { 
            
            } else if (data === "default") { 
            
            }
        });
        $(function () {
            setInterval(function () {                
                var hh = $(".mk-scroll-content li").height();                
                $(".mk-scroll-content").find("ul").animate({
                    marginTop: -hh + "px"
                }, 1000, function () {
                    $(this).css({ marginTop: "0px" }).find("li:first").appendTo(this);
                })
            }, 10000);

            setInterval(function () {                
                var hh = $(".barcontent li").height();                 
                $(".barcontent").find("ul").animate({
                    marginTop: -hh + "px"
                }, 2000, function () {
                    $(this).css({ marginTop: "0px" }).find("li:first").appendTo(this);
                })
            }, 10000);


        });
        setTimeout(function () {
            // that.ol3d.roate(false);
            that.map3d.location({
                "location" : [113.22,22.16,114,23.44]
            });
            
            that.map2d.olmap.getView().setCenter(ol.proj.transform([101.08, 42.00], 'EPSG:4326', 'EPSG:3857'));
            
            that.map2d.olmap.getView().setZoom(11);
			
        }, 10000);
    }
    /*
     * 加载右边的列表
     */
    App.prototype.loadalarm = function (options) {
        var that = this;
        
        var html = "";
        
        $.getJSON("datas/xfyj.json", function (data) {
            $.each(data, function (i, val) {
                if (val.title.length > 12) { 
                    val.title = val.title.substring(0,11);
                }
                html += "<li>" +
                "<span class='w10'><i>" + (i + 1) + "</i></span>" +
                "<span class='w20'>"+val.type+"</span>" +              
                "<span class='w70' style='text-align:left' >"+val.title+"</span>" +
                "</li>";
            });
            html = " <div class='mk-scroll-content'> <ul>" + html + " </ul>        </div>";
            $("#vpc22cdcont").html(html);
        });
      
        //定时滚动
        
       
    }
    
    /*
     * 总体图标
     * 
     */
    App.prototype.loadzttb = function (options) {
        // Generate data
        var category = [];
      
        var lineData = [];
        var barData = [];
        var gdpData = [];
        var gyData = [];
        var rjData = [];
       

        $.getJSON("datas/gy.json", function (data) {
            
            $.each(data, function (i, val) {
                category.push(val.year);
                barData.push(val.gy);
                lineData.push(val.gdp);
                gdpData.push(val.gdp);
                gyData.push(val.gy);
                rjData.push(val.rjmy);
               
            });
            
            // option
            option = {
                backgroundColor: 'rgba(0,0,0,0)',
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow',
                        label: {
                            show: true,
                            backgroundColor: '#333'
                        }
                    }
                },
                legend: {
                data: ['GDP', '工业','人均'],
                textStyle: {
                    color: '#2B80CF'
                    },
                    orient: 'vertical',
                    right: 10,
                    top: 100,
                    bottom: 20,
            }, 
            xAxis: {
                    data: category,
                    axisLine: {
                        lineStyle: {
                            color: '#2B80CF'
                        }
                    }
                },
                yAxis: {
                    splitLine: { show: false },
                    axisLine: {
                        lineStyle: {
                            color: '#2B80CF'
                        }
                    }
                },
                series: [{
                        name: '人均',
                        type: 'line',
                        smooth: true,
                        showAllSymbol: true,
                        symbol: 'emptyCircle',
                        symbolSize: 10,
                        lineStyle: {
                            normal: {
                                color: "#2B80CF"
                            }
                        },
                        data: rjData
                    }, {
                        name: '工业',
                        type: 'bar',
                        barWidth: 10,
                        itemStyle: {
                            normal: {
                                barBorderRadius: 5,
                                color: new echarts.graphic.LinearGradient(
                                    0, 0, 0, 1,
                    [
                                        { offset: 0, color: '#14c8d4' },
                                        { offset: 1, color: '#43eec6' }
                                    ]
                                )
                            }
                        },
                        data: gyData
                    }, {
                        name: 'GDP',
                        type: 'pictorialBar',
                        symbol: 'rect',
                        itemStyle: {
                            normal: {
                                color: '#0f375f'
                            }
                        },
                        symbolRepeat: true,
                        symbolSize: [12, 4],
                        symbolMargin: 1,
                        z: -10,
                        data: gdpData
                    }]
            };
            // 基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('vpc31cdcont'));
            myChart.setOption(option);
        });
        
    }
    
    App.prototype.createshow = function (options) {

    }
    
    // 返回
    return App;
})();

var app;
$(function () {
    
    app = new App();
    app.init();

})